home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 June / PersonalComputerWorld-June2009-CoverdiscCD.iso / Software / Freeware / Firebug 1.3.3 / firebug-1.3.3-fx.xpi / content / firebug / consoleInjected.js < prev    next >
Encoding:
JavaScript  |  2009-02-19  |  3.8 KB  |  83 lines

  1. /* See license.txt for terms of usage */
  2. function _FirebugConsole()
  3. {
  4.     this.log = function() { window._firebug.notifyFirebug(arguments, 'log', 'firebugAppendConsole'); }
  5.     this.debug = function() { window._firebug.notifyFirebug(arguments, 'debug', 'firebugAppendConsole'); }
  6.     this.info = function() { window._firebug.notifyFirebug(arguments, 'info', 'firebugAppendConsole'); }
  7.     this.warn = function() { window._firebug.notifyFirebug(arguments, 'warn', 'firebugAppendConsole'); }
  8.     this.error = function() { window._firebug.notifyFirebug(arguments, 'error', 'firebugAppendConsole'); }
  9.     this.assert = function() { window._firebug.notifyFirebug(arguments, 'assert', 'firebugAppendConsole'); }
  10.     this.dir = function() { window._firebug.notifyFirebug(arguments, 'dir', 'firebugAppendConsole'); }
  11.     this.dirxml = function() { window._firebug.notifyFirebug(arguments, 'dirxml', 'firebugAppendConsole'); }
  12.     this.trace = function() { window._firebug.notifyFirebug(arguments, 'trace', 'firebugAppendConsole'); }
  13.     this.group = function() { window._firebug.notifyFirebug(arguments, 'group', 'firebugAppendConsole'); }
  14.     this.groupEnd = function() { window._firebug.notifyFirebug(arguments, 'groupEnd', 'firebugAppendConsole'); }
  15.     this.groupCollapsed = function() { window._firebug.notifyFirebug(arguments, 'groupCollapsed', 'firebugAppendConsole'); }
  16.     this.time = function() { window._firebug.notifyFirebug(arguments, 'time', 'firebugAppendConsole'); }
  17.     this.timeEnd = function() { window._firebug.notifyFirebug(arguments, 'timeEnd', 'firebugAppendConsole'); }
  18.     this.profile = function() { window._firebug.notifyFirebug(arguments, 'profile', 'firebugAppendConsole'); }
  19.     this.profileEnd = function() { window._firebug.notifyFirebug(arguments, 'profileEnd', 'firebugAppendConsole'); }
  20.     this.count = function() { window._firebug.notifyFirebug(arguments, 'count', 'firebugAppendConsole'); }
  21.     this.clear = function() { window._firebug.notifyFirebug(arguments, 'clear', 'firebugAppendConsole'); }
  22.  
  23.     this.notifyFirebug = function(objs, methodName, eventID)
  24.     {
  25.         var element = this.getFirebugElement();
  26.  
  27.         var event = document.createEvent("Events");
  28.         event.initEvent(eventID, true, false);
  29.  
  30.         this.userObjects = [];
  31.         for (var i=0; i<objs.length; i++)
  32.             this.userObjects.push(objs[i]);
  33.  
  34.         var length = this.userObjects.length;
  35.         element.setAttribute("methodName", methodName);
  36.         element.dispatchEvent(event);
  37.  
  38.         //dump("FirebugConsole dispatched event "+methodName+" via "+eventID+"\n");
  39.         var result;
  40.         if (element.getAttribute("retValueType") == "array")
  41.             result = [];
  42.  
  43.         if (!result && this.userObjects.length == length+1)
  44.             return this.userObjects[length];
  45.  
  46.         for (var i=length; i<this.userObjects.length && result; i++)
  47.             result.push(this.userObjects[i]);
  48.  
  49.         return result;
  50.     };
  51.  
  52.     this.getFirebugElement = function()
  53.     {
  54.         if (!this.element)
  55.             this.element = window._getFirebugConsoleElement();
  56.         return this.element;
  57.     },
  58.     
  59.     // ***********************************************************************
  60.     // Console API
  61.  
  62.     this.__defineGetter__("firebug", function(){
  63.         return this.getFirebugElement().getAttribute("FirebugVersion");
  64.     });
  65. }
  66.  
  67. window._getFirebugConsoleElement = function()  // could this be done in extension code? but only after load....
  68. {
  69.     var element = document.getElementById("_firebugConsole");
  70.     if (!element)
  71.     {
  72.         element = document.createElementNS("http://www.w3.org/1999/xhtml","html:div"); // NS for XML/svg
  73.         element.setAttribute("id", "_firebugConsole");
  74.         element.firebugIgnore = true;
  75.          
  76.         element.setAttribute("style", "display:none");
  77.  
  78.         document.documentElement.appendChild(element);
  79.     }
  80.     return element;
  81. };
  82.  
  83.